package com.woniuxy02;

/**
 * @author 作者
 * @create 2025-06-06 10:37
 */
public class StudentService {

    public static Student[] students;

    static {
        students = new Student[3];
        students[0] = new Student(1,"a","aaa",11,"male");
        students[1] = new Student(2,"b","bbb",12,"female");
        students[2] = new Student(3,"c","ccc",13,"male");
    }

    //定义登录方法：
    //参数用户名，密码
    //返回值：学生对象
    //提示错误信息:(用户名不存在，密码错误)
    public static Student login(String name,String pwd) {
        Student findStudent = null;
        //先根据名字查找
        for(Student student : students) {
            if(name.equals(student.getName())){
                findStudent = student;
                break;
            }
        }
        if(findStudent == null){
            //用户名不存在
            throw new UserNotExistException("用户名不存在");
        }
        //验证密码
        if(!pwd.equals(findStudent.getPwd())){
            //密码错误
            throw new PasswordErrorException("密码错误");
        }
        return findStudent;
    }
//    public static Student login(String name,String pwd) {
//        Student loginStudent=null;
//        for(Student student : students) {
//            if(name.equals(student.getName()) && pwd.equals(student.getPwd())) {
//                loginStudent = student;
//            }
//        }
//        if(loginStudent!=null) {
//            return loginStudent;
//        }else{
//            throw new RuntimeException("用户名密码错误");
//        }
//    }
//    public static Student login(String name,String pwd) {
//        for(Student student : students) {
//            if(name.equals(student.getName()) && pwd.equals(student.getPwd())) {
//                return student;
//            }
//        }
//        return null;
//    }

//    public static String login(String name,String pwd)
//    public static boolean login(String name,String pwd)

}
